package com.etc.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.etc.dao.BlogMapper;
import com.etc.entity.Blog;
import com.etc.entity.BlogComnent;
import com.etc.entity.BlogName;
import com.etc.entity.Restaurant;
import com.etc.service.BlogService;
import com.etc.utils.PageData;

@Service(value = "blogService")
public class BlogServiceImpl implements BlogService {

	// 调用blogDao[BlogMapper]
	// 所以注入对象
	@Resource
	private BlogMapper blogMapper;

	@Override
	public int selectCount(String content) {

		return blogMapper.selectCount(content);
	}

	@Override

	public boolean updateByPrimaryKey(Integer blogid) {

		return blogMapper.updateByPrimaryKey(blogid);
	}

	@Override
	public boolean addBlog(Blog blog) {
		// TODO Auto-generated method stub
		return blogMapper.addBlog(blog) > 0;

	}

	@Override
	public PageData<BlogName> selectAllBlog(Integer page, Integer pagesize, String content) {
		// TODO Auto-generated method stub
		// 起始位置
		int start = (page - 1) * pagesize;

		// 查询需要返回的数据
		List<BlogName> data = blogMapper.selectAllBlog(start, pagesize, content);
		int count = blogMapper.selectCount(content);
		PageData<BlogName> pd = new PageData<>(data, count, pagesize, page);
		return pd;
	}

	@Override
	public boolean updateAudit(Integer bid) {
		// TODO Auto-generated method stub
		return blogMapper.updateAudit(bid);
	}

	@Override
	public List<BlogComnent> selectComment(Integer bid) {
		// TODO Auto-generated method stub
		return blogMapper.selectComment(bid);
	}

	/**
	 * 查询博客所有信息
	 */
	@Override
	public List<Blog> getAllBlog() {
		// TODO Auto-generated method stub
		return blogMapper.getAllBlog();
	}

	/**
	 * 分页
	 */
	@Override
	public PageData<Blog> selectAllBlogByPage(Integer page, Integer pageSize, String content) {
		// TODO Auto-generated method stub
		// 起始位置
		int start = (page - 1) * pageSize;

		// 查询需要返回的数据
		List<BlogName> data = blogMapper.selectAllBlog(start, pageSize, content);
		int count = blogMapper.selectCount(content);
		PageData<Blog> pd = new PageData(data, count, pageSize, page);
		return pd;
	}

	@Override
	public int selectCountByContent(String content) {
		// TODO Auto-generated method stub
		return blogMapper.selectCount(content);
	}

	@Override
	public boolean updateBlog(Blog blog) {
		// TODO Auto-generated method stub
		return blogMapper.updateBlog(blog);
	}

	@Override
	public PageData<Blog> selectPhoto(Integer page, Integer pagesize, String content) {
		// TODO Auto-generated method stub
		int start = (page - 1) * pagesize;

		// 查询需要返回的数据
		List<Blog> data = blogMapper.selectPhoto(start, pagesize, content);
		int count = blogMapper.selectCount(content);
		PageData<Blog> pd = new PageData<>(data, count, pagesize, page);
		return pd;
	}

	@Override
	public boolean deleteByPrimaryKey(int bcid) {
		// TODO Auto-generated method stub
		boolean flog = blogMapper.deleteByPrimaryKey(bcid);
		return flog;
	}

	@Override
	public List<Blog> getBlogByPage(Integer page, Integer limit) {
	int start = (page-1)*limit;
		return blogMapper.getBlogByPage(start,limit);
	}

	@Override
	public int getcount() {
		
		return blogMapper.getcount();
	}

	@Override
	public List<Blog> getblogs() {
		
		return blogMapper.getblogs();
	}

}
